package test1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        /*
        1. 在项目下创建TCP 服务器端 端口号为8888
        2. 等待客户端连接，如果有客户端连接则获取到客户端对象
        3. 在获取到客户端对象之后 在服务器读取客户端传送的数据
         */
        ServerSocket ss=new ServerSocket(8888);
        System.out.println("服务端开启");

        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }

        System.out.println("服务端已关闭");
        accept.close();
        ss.close();
    }
}
